# pip install langchain-mcp-adapters
from major.models_manager import chat_model
from langchain_mcp_adapters.client import MultiServerMCPClient
from langgraph.prebuilt import create_react_agent

client = MultiServerMCPClient(
    {
        "demo_serve": {
            "url": "http://127.0.0.1:8001/mcp",
            "transport": "streamable_http",
        },

    },
)

async def stream_response():
    tools = await client.get_tools()

    agent = create_react_agent(
        chat_model.get_model(),
        tools,
    )
    response = await agent.ainvoke(
        {"messages": [{"role": "user", "content": "现在几点"}]}
    )
    print(response["messages"][-1].content)
if __name__ == "__main__":
    import asyncio
    asyncio.run(stream_response())